﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace INSTA.Concepts.Reflection
{
    class Program
    {
        static void Main(string[] args)
        {
            //Test_GetProperty();
            //Test_List();
            //Test_SetProperty();
            //Test_CallMethod_NoParamsOrReturnType();

            Test_CallMethod_WithParamsAndReturnType();
        }


        public static void Test_GetProperty()
        {
            var p = new Person();

            int result = (int)ReflectionHelper.GetPropertyValue(p, "theValue");

            Console.WriteLine("TheValue : {0}", result  );
        }

        public static void Test_GetProperty_Generic()
        {
            var p = new Person();

            DummyClass result = ReflectionHelper.GetPropertyValue<DummyClass>(p, "GetDummy");

            Console.WriteLine("TheValue : {0}", result);
        }

        public static void Test_SetProperty()
        {
            var p = new Person();

            ReflectionHelper.SetPropertyValue(p, "theValue", 55);

            Console.WriteLine( p.theValue );

        }

        public static void Test_CallMethod_NoParamsOrReturnType()
        {
            var p = new Person();

            ReflectionHelper.CallMethod(p, "SayHello", null);
        }

        public static void Test_CallMethod_WithParamsAndReturnType()
        {
            var p = new Person();

            long result = (long)ReflectionHelper.CallMethod(p, "Add", 15,22);

            Console.WriteLine(result  );
        }







        public static void Test_List()
        {
            Type type = typeof(StringBuilder);

            // On fait imprimer la liste de toutes les méthodes
            // de l'objet Type en cours.

            Console.WriteLine("== Methods == {0}", "\r\n");
            foreach (var m in type.GetMethods())
            {
                Console.WriteLine(m.Name);
            }

            Console.WriteLine("== Constructors == {0}", "\r\n");
            foreach (var m in type.GetConstructors())
            {
                foreach (var param in m.GetParameters())
                {
                    Console.WriteLine("{0}({1} {2})",
                                      m.Name,
                                      param.ParameterType.Name,
                                      param.Name);
                }



            }


            Console.WriteLine();

            Console.WriteLine("== Properties == {0}", "\r\n");
            foreach (var m in type.GetProperties())
            {
                Console.WriteLine("{0} : {1}", m.Name, m.PropertyType.Name);
            }
        }


    }
}
